package com.lvy.hczn.transmit.controller.unuse;

import com.lvy.hczn.front.common.core.domain.AjaxResult;
import com.lvy.hczn.front.common.exception.UtilException;
import com.lvy.hczn.front.system.domain.business.PackSpu;
import com.lvy.hczn.mq.rocket.ParamInfo;
import com.lvy.hczn.transmit.domain.dto.cteck.GoodsBag;
import com.lvy.hczn.transmit.service.GoodsBagService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RequestMapping("/api/dt/bag/")
@RestController
@Slf4j
public class GoodsBagController {

    @Autowired
    private GoodsBagService goodsBagService;


    @ApiOperation(value = "商品包装袋从平台同步", notes = "商品包装袋从平台同步")
    @PostMapping("data")
    public AjaxResult syncGoodsBagFromPlatform(HttpServletRequest request, @RequestBody ParamInfo<GoodsBag> info) {
        try {
            goodsBagService.syncGoodsBagFromPlatform(request, info);
            return AjaxResult.success();
        } catch (Exception e) {
            if (e instanceof UtilException) {
                return AjaxResult.error(e.getMessage());
            } else {
                log.error("syncGoodsBagFromPlatform同步异常：{}", e);
                return AjaxResult.error("系统异常");
            }
        }
    }

    @ApiOperation(value = "商品包装袋同步到仓库", notes = "商品包装袋同步到仓库")
    @PostMapping("/wh/data")
    public AjaxResult syncGoodsBagFromTransmit(HttpServletRequest request, @RequestBody ParamInfo<PackSpu> info) {
        try {
            goodsBagService.syncGoodsBagFromTransmit(request, info);
            return AjaxResult.success();
        } catch (Exception e) {
            if (e instanceof UtilException) {
                return AjaxResult.error(e.getMessage());
            } else {
                log.error("syncGoodsBagFromTransmit同步异常：{}", e);
                return AjaxResult.error("系统异常");
            }
        }
    }
}
